﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _01_委托练习
{
    public delegate void ChangeLabel(string dateTime);
    public delegate void ChangeButtonEnabled(bool enable);

    public partial class Form1 : Form
    {
        Form2 form2 = null;
        public static ChangeLabel changeLabel;
        public static ChangeButtonEnabled changeButtonEnabled;

        public Form1()
        {
            InitializeComponent();
            changeLabel = new ChangeLabel(ChangeLabelText);
            changeButtonEnabled = new ChangeButtonEnabled(ChangeButtonEnabled);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            form2 = new Form2();
            form2.Show();
            this.button2.Enabled = false;
        }

        public void ChangeButtonEnabled(bool enable)
        {
            this.button2.Enabled = enable;
        }


        private void button1_Click(object sender, EventArgs e)
        {
            form2?.ChangeLabelText(DateTime.Now.ToString());
        }

        /// <summary>
        /// 修改标签文本
        /// </summary>
        /// <param name="dateTime"></param>
        public void ChangeLabelText(string dateTime)
        {
            this.label1.Text = dateTime;
        }

    }
}
